home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / gfx / 3d / irit50src.lha / irit5 / prsr_lib / trim_wrt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-29  |  6.6 KB  |  153 lines

  1. /******************************************************************************
  2. * Trim_Wrt.c - Trimmed surfaces writing to files.                  *
  3. *******************************************************************************
  4. * Written by Gershon Elber, Dec. 94.                          *
  5. ******************************************************************************/
  6.  
  7. #include <string.h>
  8. #include "prsr_loc.h"
  9.  
  10. /*****************************************************************************
  11. * DESCRIPTION:                                                               M
  12. * Generic routine to write a trimmed surface to the given file.             M
  13. *   If Comment is NULL, no comment is printed, if "" only internal comment.  M
  14. *                                                                            *
  15. * PARAMETERS:                                                                M
  16. *   TrimSrfs:  To be saved in stream.                                        M
  17. *   FileName:  File name where output should go to.                          M
  18. *   Indent:    Column in which all printing starts at.                       M
  19. *   Comment:   Optional comment to describe the geometry.                    M
  20. *   ErrStr:    If failed, ErrStr will be set to describe the problem.        M
  21. *                                                                            *
  22. * RETURN VALUE:                                                              M
  23. *   int:        TRUE if succesful, FALSE otherwise.                          M
  24. *                                                                            *
  25. * KEYWORDS:                                                                  M
  26. *   TrimWriteTrimmedSrfToFile, files, write                                  M
  27. *****************************************************************************/
  28. int TrimWriteTrimmedSrfToFile(TrimSrfStruct *TrimSrfs,
  29.                   char *FileName,
  30.                   int Indent,
  31.                   char *Comment,
  32.                   char **ErrStr)
  33. {
  34.     int i, Handler;
  35.     FILE *f;
  36.  
  37.     if ((f = fopen(FileName, "w")) == NULL) {
  38.     *ErrStr = "Fail to open file";
  39.     return FALSE;
  40.     }
  41.     Handler = IritPrsrOpenStreamFromFile(f, FALSE,
  42.                      IritPrsrSenseBinaryFile(FileName),
  43.                      FALSE);
  44.  
  45.     i = TrimWriteTrimmedSrfToFile2(TrimSrfs, Handler, Indent, Comment, ErrStr);
  46.  
  47.     IritPrsrCloseStream(Handler, TRUE);
  48.  
  49.     return i;
  50. }
  51.  
  52. /*****************************************************************************
  53. * DESCRIPTION:                                                               M
  54. * Generic routine to write trimmed surface(s) to the given stream.         M
  55. *   If Comment is NULL, no comment is printed, if "" only internal comment.  M
  56. *                                                                            *
  57. * PARAMETERS:                                                                M
  58. *   TrimSrfs:  To be saved in stream.                                        M
  59. *   Handler:   A handler to the open stream.                     M
  60. *   Indent:    Column in which all printing starts at.                       M
  61. *   Comment:   Optional comment to describe the geometry.                    M
  62. *   ErrStr:    If failed, ErrStr will be set to describe the problem.        M
  63. *                                                                            *
  64. * RETURN VALUE:                                                              M
  65. *   int:        TRUE if succesful, FALSE otherwise.                          M
  66. *                                                                            *
  67. * KEYWORDS:                                                                  M
  68. *   TrimWriteTrimmedSrfToFile2, files, write, stream                         M
  69. *****************************************************************************/
  70. int TrimWriteTrimmedSrfToFile2(TrimSrfStruct *TrimSrfs,
  71.                    int Handler,
  72.                    int Indent,
  73.                    char *Comment,
  74.                    char **ErrStr)
  75. {
  76.     if (Comment != NULL) {
  77.     _IPFprintf(Handler, Indent, "#\n");
  78.     _IPFprintf(Handler, Indent,
  79.            "# cagd_lib - Bspline Trimmed surface(s) dump.\n");
  80.     _IPFprintf(Handler, Indent, "#\n");
  81.     _IPFprintf(Handler, Indent, "# %s\n", Comment);
  82.     _IPFprintf(Handler, Indent, "#\n");
  83.     }
  84.  
  85.     *ErrStr = NULL;
  86.  
  87.     for ( ; TrimSrfs != NULL; TrimSrfs = TrimSrfs -> Pnext) {
  88.     TrimCrvStruct
  89.         *TCrvs = TrimSrfs -> TrimCrvList;
  90.  
  91.     _IPFprintf(Handler, Indent, "[TRIMSRF\n");
  92.     if (!CagdSrfWriteToFile2(TrimSrfs -> Srf, Handler, Indent + 4,
  93.                  NULL, ErrStr))
  94.         return FALSE;
  95.  
  96.     for ( ; TCrvs != NULL; TCrvs = TCrvs -> Pnext) {
  97.         TrimCrvSegStruct
  98.         *TSCrvs = TCrvs -> TrimCrvSegList;
  99.  
  100.         _IPFprintf(Handler, Indent + 4, "[TRIMCRV\n");
  101.  
  102.         for ( ; TSCrvs != NULL; TSCrvs = TSCrvs -> Pnext) {
  103.         _IPFprintf(Handler, Indent + 8, "[TRIMCRVSEG\n");
  104.  
  105.         if (!CagdCrvWriteToFile2(TSCrvs -> UVCrv, Handler, Indent + 12,
  106.                      NULL, ErrStr))
  107.             return FALSE;
  108.  
  109.         _IPFprintf(Handler, Indent + 8, "]\n");
  110.         }
  111.  
  112.         _IPFprintf(Handler, Indent + 4, "]\n");
  113.     }
  114.  
  115.     _IPFprintf(Handler, Indent, "]\n");
  116.     }
  117.  
  118.     return *ErrStr == NULL;
  119. }
  120.  
  121. /*****************************************************************************
  122. * DESCRIPTION:                                                               M
  123. * Generic routine to write trimmed surface(s) to the given stream.         M
  124. *   If Comment is NULL, no comment is printed, if "" only internal comment.  M
  125. *                                                                            *
  126. * PARAMETERS:                                                                M
  127. *   TrimSrfs:  To be saved in stream.                                        M
  128. *   f:         File descriptor where output should go to.                    M
  129. *   Indent:    Column in which all printing starts at.                       M
  130. *   Comment:   Optional comment to describe the geometry.                    M
  131. *   ErrStr:    If failed, ErrStr will be set to describe the problem.        M
  132. *                                                                            *
  133. * RETURN VALUE:                                                              M
  134. *   int:        TRUE if succesful, FALSE otherwise.                          M
  135. *                                                                            *
  136. * KEYWORDS:                                                                  M
  137. *   CagdSrfWriteToFile3, files, write                                        M
  138. *****************************************************************************/
  139. int TrimWriteTrimmedSrfToFile3(TrimSrfStruct *TrimSrfs,
  140.                    FILE *f,
  141.                    int Indent,
  142.                    char *Comment,
  143.                    char **ErrStr)
  144. {
  145.     int Handler = IritPrsrOpenStreamFromFile(f, FALSE, FALSE, FALSE),
  146.     i = TrimWriteTrimmedSrfToFile2(TrimSrfs, Handler, Indent,
  147.                        Comment, ErrStr);
  148.  
  149.     IritPrsrCloseStream(Handler, TRUE);
  150.  
  151.     return i;
  152. }
  153.